﻿using System;
using UnityEngine;

namespace Component.Passenger
{
    public class PassengerNode : MonoBehaviour
    {
        [SerializeField] private float sideLength = 1;
        
        private int targetStation;
        private DrawMeshTools meshTool;

        public int ParentId { get; set; }
        public DrawMeshTools.MeshType Type { get; set ;}

        private DrawMeshTools.MeshType type;

        public int TargetStation
        {
            get
            {
                return targetStation;
            }
            set
            {
                targetStation = value;
            }
        }


        private void Awake()
        {
            meshTool = gameObject.AddComponent<DrawMeshTools>();
            meshTool.SortLayer = 2;
        }

        private void Start()
        {
            switch (type)
            {
                case DrawMeshTools.MeshType.Round:
                case DrawMeshTools.MeshType.Quad:
                    sideLength = .3f;
                    break;
                case DrawMeshTools.MeshType.Triangle:
                    sideLength = .4f;
                    break;
                default:
                    PassengerGeneration.ResetPassenger(this);
                    break;
            }
            if (Type == DrawMeshTools.MeshType.Triangle)
            {
                meshTool.DrawTriangle(transform.position, sideLength, Color.black);
            }
            else
            {
                meshTool.DrawMesh(Type, transform.position, sideLength, Color.black);
            }
            type = Type;
        }

        private void Update()
        {
            if (type != Type)
            {
                if (Type == DrawMeshTools.MeshType.Triangle)
                {
                    meshTool.DrawTriangle(transform.position, sideLength, Color.black);
                }
                else
                {
                    meshTool.DrawMesh(Type, transform.position, sideLength, Color.black);
                }
                type = Type;
            }
        }
    }
}